//
//  YCLoginBaseViewController.m
//  HeartWorldClient
//
//  Created by 董知樾 on 2017/7/17.
//  Copyright © 2017年 谭明权. All rights reserved.
//

#import "YCLoginBaseViewController.h"

@interface YCLoginBaseViewController ()

@end

@implementation YCLoginBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = [UIColor colorWithRGBValue:0xcdcdcd];
    [self.view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self.view);
        make.height.mas_equalTo(1);
    }];
    [self setBackItem];
    
    [self addKeyboardCorverNotification];
}

- (void)setBackItem {
    UIImage *img = [UIImage imageNamed:@"返回"];
    img = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIButton *navBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 5, 40, 30)];
    
    navBtn.imageEdgeInsets= UIEdgeInsetsMake(0, -30, 0, 0);
    [navBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [navBtn setImage:img forState:UIControlStateNormal];
    
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:navBtn];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    UINavigationBar *navBar = self.navigationController.navigationBar;
    navBar.barTintColor= [UIColor whiteColor];
    
    NSMutableDictionary *md = [NSMutableDictionary dictionary];
    md[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    md[NSForegroundColorAttributeName] = [UIColor colorWithRGBValue:0x333333];
    
    [navBar setTitleTextAttributes:md];
    [UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleDefault;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    UINavigationBar *navBar = self.navigationController.navigationBar;
    if (!navBar) {
        UIViewController *root = [UIApplication sharedApplication].keyWindow.rootViewController;
        if ([root isKindOfClass:[UITabBarController class]]) {
            UINavigationController *navi = ((UITabBarController *) root).selectedViewController;
            navBar = navi.navigationBar;
        } else {
            
            navBar = ((UINavigationController *) root).navigationBar;
        }
    }
    
    navBar.barTintColor = BackgroundColor;
    
    NSMutableDictionary *md = [NSMutableDictionary dictionary];
    md[NSFontAttributeName] = [UIFont systemFontOfSize:20];
    md[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [navBar setTitleTextAttributes:md];
    [UIApplication sharedApplication].statusBarStyle= UIStatusBarStyleLightContent;
}

- (void)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}


@end
